#include <stdio.h>
#include <stdlib.h>

typedef struct LinkedNode
{
    int data;
    LinkedNode *next;
} LinkedNode;

typedef struct LinkedQueue
{
    LinkedNode *front, *rear;
} LinkedQueue;

void Print(LinkedQueue Q)
{
    LinkedNode *p = Q.front->next;
    printf("front->");
    while (p != NULL)
    {
        printf("%d->", p->data);
        p = p->next;
    }
    printf("rear\n");
}

void InitQueue(LinkedQueue &Q)
{
    Q.front = Q.rear = (LinkedNode *)malloc(sizeof(LinkedNode));
    Q.front->next = NULL;
    printf("初始化\n");
    Print(Q);
}

bool IsEmpty(LinkedQueue Q)
{
    if (Q.front == Q.rear)
        return true;
    return false;
}

void EnQueue(LinkedQueue &Q, int e)
{
    LinkedNode *s = (LinkedNode *)malloc(sizeof(LinkedNode));
    s->data = e;
    s->next = NULL;
    Q.rear->next = s;
    Q.rear = s;
    printf("%d 入队: \n", e);
    Print(Q);
}

bool DeQueue(LinkedQueue &Q, int &e)
{
    if (IsEmpty(Q))
        return false;
    LinkedNode *p = Q.front->next;
    e = p->data;
    Q.front->next = p->next;
    if (Q.rear == p)
        Q.rear = Q.front;
    free(p);
    printf("%d 出队: \n", e);
    Print(Q);
    return true;
}

int main()
{
    LinkedQueue Q;
    int e;
    InitQueue(Q);
    EnQueue(Q, 3);
    EnQueue(Q, 4);
    EnQueue(Q, 5);
    DeQueue(Q, e);
    DeQueue(Q, e);
    DeQueue(Q, e);
    return 0;
}